package com.mirror.llk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.mirror.llk.logic.ThemeLogic;
import com.mirror.llk.view.ThemeChooseView;
import com.mirror.utils.AnimationUtil;
import com.mirror.utils.base.Page;
import com.mirror.utils.view.CustomListView.OnRefreshLoadListener;

public class ThemeChooseActivity extends Activity {

	private static final String TAG = "ThemeChooseActivity";

	private ThemeChooseView chooseView;

	private ThemeLogic logic = new ThemeLogic();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		chooseView = new ThemeChooseView(this);
		setContentView(chooseView);
		init();
		load();
	}

	private void init() {
		chooseView.listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View arg1, int index, long arg3) {
				Intent intent = new Intent(ThemeChooseActivity.this, GameMainActivity.class);
				ThemeChooseActivity.this.startActivity(intent);
			}
		});
		chooseView.listView.setOnRefreshLoadListener(new OnRefreshLoadListener() {

			@Override
			public void onRefresh(Page page) {
				chooseView.listView.setLayoutAnimation(AnimationUtil.getAnimation());
				logic.queryThemeChoosePage(chooseView, page);
			}

			@Override
			public void onLoadMore(Page page) {
				logic.queryThemeChoosePage(chooseView, page);
			}

		});
		chooseView.btnDiy.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ThemeChooseActivity.this, DIYActivity.class);
				ThemeChooseActivity.this.startActivityForResult(intent, 1);
			}
		});
		chooseView.tvDownload.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ThemeChooseActivity.this, ThemeDownloadActivity.class);
				ThemeChooseActivity.this.startActivity(intent);
			}
		});
	}

	private void load() {
		chooseView.listView.load();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
			case 1:
				switch (resultCode) {
					case Activity.RESULT_OK:// 创建主题完成
						this.load();
						break;
				}
				break;
			default:
				;
		}
	}
}
